<?php
include_once(PATH_APP_COMMON . "AuthManager.php");
abstract class Controller_AdminCategory extends Controller {

	protected $_tplForCreate = 'Category_Create';
	protected $_tplForEdit = 'Category_Create';
	protected $_tplForList = 'Category_List';

	function actionIndex()
	{
		$this->redirect($this->url('List'));
	}

	function actionRemove()
	{
		$id = _gp('id','int');
		$ids = $this->getChildren($id,1,1,'string');
		$this->remove($ids);
		$this->success(MESSAGE_SUCCESS);
	}

	function actionCreate()
	{
		$data['pid'] = _gp("pid",'int');
		$pids = $this->getOption();
		$this->assign("pids",$pids);
		$this->assign("data",$data);
		$this->display($this->_tplForCreate);
	}

	function actionSave(){
		$this->save($_POST);
		$this->success("操作成功！");
	}

	function actionEdit(){
		$id = _gp('id','int');
		$data = $this->be($id);
		$pids = $this->getOption();
		$this->assign("pids",$pids);
		$this->assign("data",$data);
		$this->display($this->_tplForEdit);
	}

	function actionList()
	{
		$this->setBack();
		$data = $this->getChildren(-1, false, $recursive=true, "array_detail");
		$this->assign("data",$data);
		$this->display($this->_tplForList);
	}

	function actionBatch(){
		$data = $_POST['data'];
		$do = _gp("do",'string');
		switch ($do){
			case "order":
				foreach ($data as $id => $row){
					$row['id'] = $id;
					$this->save($row);
				}
			break;
		}
		$this->goBack(MESSAGE_SUCCESS);
	}
}
